﻿Imports System.IO
Public Class UserControlSaoLuuPhucHoi
    'chon duong dan den noi can sao luu
    Private Sub btnChon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChon.Click
        Try
            Dim open As New OpenFileDialog()
            With open
                open.Filter = "Tap tin .mdb|*.mdb"
                '.FilterIndex = 1
                .Title = "Demo Open File Dialog"
            End With

            If open.ShowDialog() = DialogResult.OK Then
                txtSaoLuu.Text = open.FileName
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        
    End Sub
    'sao luu
    Private Sub btnSaoLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaoLuu.Click

        Dim luu As New SaveFileDialog()
        luu.Filter = "Tap tin .bak|*.bak"
        If luu.ShowDialog = DialogResult.OK Then
            Try
                Dim f As FileInfo = New FileInfo(txtSaoLuu.Text)
                Dim str As String = luu.FileName
                'txtPhucHoi.Text = luu.FileName
                f.CopyTo(str)
                MessageBox.Show("Sao lưu thành công")
            Catch ex As Exception
                MessageBox.Show("Sao lưu thất bại")
            End Try
            
        End If
    End Sub
    'lay duong dan file can phuc hoi
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim open As New OpenFileDialog()
            open.Filter = "Tap tin .bak|*.bak"
            If open.ShowDialog = DialogResult.OK Then
                txtPhucHoi.Text = open.FileName
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        
    End Sub
    'thuc hien phuc hoi
    Private Sub btnPhucHoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPhucHoi.Click
        Dim luu As New SaveFileDialog()
        luu.Filter = "Tap tin .mdb|*.mdb"
        If luu.ShowDialog = DialogResult.OK Then
            Try
                Dim f As FileInfo = New FileInfo(txtPhucHoi.Text)
                Dim str As String = luu.FileName
                'txtPhucHoi.Text = luu.FileName
                f.CopyTo(str)
                MessageBox.Show("Phục hồi thành công")
            Catch ex As Exception
                MessageBox.Show("Phục hồi thất bại")
            End Try

        End If

    End Sub

    Private Sub UserControlSaoLuuPhucHoi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' txtSaoLuu.Text = "QUANLYSOTIETKIEM.mdb"
    End Sub
End Class
